package com.dwin.dingnuo.views;

import android.app.Activity;
import android.app.Dialog;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.TextView;

import com.dwin.dingnuo.R;


/**
 * 添加设备对话框 （一键配网，扫码添加设备，添加设备）
 */
public class AddDeviceDialog implements OnClickListener {
    private Dialog mDialog = null;
    private Activity mActivity = null;

    private ClickBack clickBack;
    public AddDeviceDialog(Activity act) {
        mActivity = act;
    }

    /**
     * 显示设置头像选择对话框
     */
    public void popSelectDialog() {
        setDialog();
        mDialog.show();
    }

    /**
     * 设置dialog窗口样式 布局 点击事件
     */
    private void setDialog() {
        // 此处直接new一个Dialog对象出来，在实例化的时候传入主题
        if (mDialog == null) {
            mDialog = new Dialog(mActivity, R.style.DialogTheme);
            mDialog.setContentView(R.layout.dialog_add_device);
            mDialog.setCanceledOnTouchOutside(true);
            Window window = mDialog.getWindow();
            window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            window.setGravity(Gravity.BOTTOM);
            window.setWindowAnimations(R.style.dialog_style);
            window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

            TextView tv_option00 =  mDialog.findViewById(R.id.tv_option00);
            tv_option00.setOnClickListener(this);
            TextView tv_option01 =  mDialog.findViewById(R.id.tv_option01);
            tv_option01.setOnClickListener(this);
            TextView tv_option02 =  mDialog.findViewById(R.id.tv_option02);
            tv_option02.setOnClickListener(this);
            TextView tv_option03 =  mDialog.findViewById(R.id.tv_option03);
            tv_option03.setOnClickListener(this);

            TextView cancelTxt = mDialog.findViewById(R.id.select_cancel);
            cancelTxt.setOnClickListener(this);
        }
    }

    /**
     * 处理各控件点击事件
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_option00:
                if (clickBack != null) {
                    clickBack.clickOption00();
                }
                break;
            case R.id.tv_option01:
                if (clickBack != null) {
                    clickBack.clickOption01();
                }
                break;
            case R.id.tv_option02:
                if (clickBack != null) {
                    clickBack.clickOption02();
                }
                break;
            case R.id.tv_option03:
                if (clickBack != null) {
                    clickBack.clickOption03();
                }
                break;

            case R.id.select_cancel:
                break;
        }
        mDialog.dismiss();
    }

    public void setCallBack(ClickBack clickBack) {
        this.clickBack = clickBack;
    }

    public interface ClickBack {
        void clickOption00();
        void clickOption01();
        void clickOption02();
        void clickOption03();
    }

}
